#ifndef RefCounted_First
#define RefCounted_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Object.h"

//---- RefCounted --------------------------------------------------------------

class RefCounted : public Object {
public:
	MetaDef(RefCounted);
	RefCounted();
	void Ref();
#       define SafeRef(p) { if (p) p->Ref(); }
	void Unref();
#       define SafeUnref(p) { if (p) { p->Unref(); p= 0; } }
	void InitNew();
	static void Assign(RefCounted **to, RefCounted *from);
#       define AssignRef(to,from) RefCounted::Assign((RefCounted**)(to), (from))

protected:
	~RefCounted();

private:
	int refcnt;
};

inline void RefCounted::Ref()
	{ refcnt++; }

#endif

